<?php
/**
 * 用户表数据操作层
 * @author yangchao
 * @package user
 * @copyright yangchao
 * @version 1.0
 * @code-encode utf-8
 * @data-encode 2011-01-17
 */

class db_user_login extends db_base {
    
	var $table_name = "user_login";
	
	function db_user_info()
	{
		parent::db_base();
	}

	/**
	 * 前台取用户当天登录信息
	 * @param $uid
	 */
	function get_user_login_item_by_uid($uid,$date)
	{
		
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER_ITEM;
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_alllist($this->table_name,1,1,"","uid='{$uid}' and login_date = '{$date}' and status=1");
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_TIME_USER_ITEM);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	/**
	 * 用户添加当天登录信息
	 * @param $user_name
	 * @param $password
	 */
	function insert_user_login($uid,$user_nickname)
	{
		// 插入数据
		$ary = array();

		$ary["uid"] = $uid;
		$ary["user_nickname"] = $user_nickname;
		$ary["login_date"] = Date::get_date();
		
		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["update_time"] = Date::get_date_time();
		$ary["update_ip"] = IP::get_client_ip_long();
		$ary["status"] = 1;
		
		$ret = $this->insert($this->table_name, $ary);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $ret;
	}
	
	

}



